//array list sort
package test_pack;
import java.util.*;

public class ArrLst {

	public static void main(String[] args){
	
		int arrRow = 4;
		int arrCol = 3;
		
		ArrayList<ArrayList <Integer>> arr1 = randArrLst(arrRow, arrCol);
		System.out.println("Start:");
		showArrLst(arr1, arrRow, arrCol);
		System.out.print("\n");
		System.out.print("\n");
		System.out.println("Sorted:");
		ArrayList<ArrayList <Integer>> arr2 = sortArrLst(arr1);
		showArrLst(arr2, arrRow, arrCol);
	}
	public static void showArrLst(ArrayList<ArrayList<Integer>> arr, int a, int b){
		
		for(int j = 0; j < b; j++){
			System.out.print("\n");
			for(int i = 0; i < a; i++){
				System.out.print(arr.get(j).get(i) + "\t");
			}
			
		}
		
	}
	public static ArrayList<ArrayList<Integer>> randArrLst(int arrCol, int arrRow){
		
		ArrayList<ArrayList <Integer>> arr = new ArrayList<ArrayList <Integer>>();
		
		for(int j = 0; j < arrRow; j++){
			 arr.add(j, new ArrayList<Integer>());
			for(int i = 0; i < arrCol; i++){
					
				arr.get(j).add(i,new Integer ((int)(Math.random()*10)));
			}
			
		}
		return arr;
	}
	
	public static ArrayList<ArrayList<Integer>> sortArrLst(ArrayList<ArrayList<Integer>> arr){
		
		
	    	int buff = 0;        
	        for (int r = 0; r < arr.get(0).size(); r++) {
	        for (int i = 0; i < arr.size(); i++) {
	            for (int j = 0; j < arr.get(0).size() - 1; j++) {
	                if ((arr.get(i).get(j).intValue()) > (arr.get(i).get(j+1)).intValue()) {
	                    buff = (arr.get(i).get(j));
	                    arr.get(i).set(j, (arr.get(i).get(j+1)));
	                    arr.get(i).set(j+1, buff);
	                }
	            }            
	        }
				
	        }
			return arr;
	} 
}
